$("button.login").click(function() {
    Util.jumpUrl({
        file: 'center.html',
        cmd: 'login',
        try: 0,
    });
});
$("button.register").click(function() {
    Util.jumpUrl({
        file: 'center.html',
        cmd: 'register',
        try: 0,
    });
});

// 站点是否已关闭
Classify.queryExt("settings", "mainten", true, {}, function(v) {
    if (v.close) {
        $("body").hide();
        alert("站点已关闭\n" + v.content);
    }
});

// 实现公告的滚动效果
$(document).ready(function() {
    if ($("#marquee").marquee)
        $("#marquee").marquee();
});

$(".footer .gamehall").click(function() {
    if (!logined) alert2("请先登录！");
    else
        Util.jumpUrl({
            file: 'center.html',
            cmd: 'gamecenter',
        });
});
$(".footer .money").click(function() {
    if (!logined) alert2("请先登录！");
    else if (urlInfo.params.try == 1) alert2("游客不允许此操作！");
    else
        Util.jumpUrl({
            file: 'center.html',
            cmd: 'charge',
            back: encodeURIComponent(window.location.href),
        });
});
$(".footer .me").click(function() {
    if (!logined) alert2("请先登录！");
    else
        Util.jumpUrl({
            file: 'center.html',
            cmd: 'index',
        });
});

// 网站名称
Classify.query("settings", "title", false, "中盈", function(v) {
    $("title").html("登录 - " + v);
    $(".copyright span").html(v);
});

// 网站LOGO
if (urlInfo.params.bocai == 1) {
    $(".logo img").attr("src", "");
    $("li.pc").hide();
}
else
    Classify.queryExt("settings", "logo-small", false, "", function(v) {
        if (v) {
            $(".logo img").hide();
        }
    });

// 公告
Classify.queryExt("settings", "board", false, "", function(v) {
    $("#marquee li").html(v);
});

// 广告图片
Classify.queryExt("settings", "ads_phone", true, [], function(ads) {
    $(function() {
        var index = 0;
        for (var i = 1; i <= 5; i++) {
            if (!ads[i]) continue;
            $("#demo-slider").flexslider('addSlide', '<li><img src="' + ads[i] + '"/></li>', index++);
        }
        $("#demo-slider").flexslider("removeSlide", index);
    });
});

// 检查下用户是否已经处于登录状态
var logined = false;
function queryTimer() {
    ME.query(function(r) {
        if (r) {
            // 处于登录状态
            logined = true;
            setTimeout(queryTimer, 10*1000);
        }
        else {
            logined = false;
        }

        // 刷新下界面
        Login.redraw();
    });
}
queryTimer();

$("#user-info .center").click(function() {
    // 跳转到个人中心
    Util.jumpUrl({
        file: 'center.html',
        cmd: 'index',
    });
});
$("button.logout").click(function() {
    ME.logout();
    window.location.href = "index.html";
});
$("button.gamehall").click(function() {
    if (!logined) {
        alert2("请先登录！");
        return;
    }
    Util.jumpUrl({
        file: 'center.html',
        cmd: 'gamecenter',
    });
});
$("button.money").click(function() {
    if (!logined) {
        alert2("请先登录！");
        return;
    }
    Util.jumpUrl({
        file: 'center.html',
        cmd: 'charge',
        back: encodeURIComponent(window.location.href),
    });
});
$("li.pc a").click(function() {
    window.location.href = "../pc/index.html?sid=" + (Util.sid || '') + '&try=' + (urlInfo.params.try || 0);
});
$(".hot-games li").click(function(e) {
    var game = $(e.currentTarget).attr("class");
    if (game == "more") {
        if (!logined) {
            alert2("请先登录！");
            return;
        }
        Util.jumpUrl({
            file: 'center.html',
            cmd: 'gamecenter',
        });
        return;
    }
    if (game == "kefu") {
        _MEIQIA('showPanel');
        return;
    }
    if (game == "kefu" || game == "try" || game == "pc") return;

    if (!logined) {
        alert2("请先登录！");
        return;
    }
    Util.jumpUrl({
        file: 'main2.html',
        game: game,
    });
});
